﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class MapInfo_DepartmentImage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) 
            Bind(0);

       
    }

   public void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        Bind(PageIndex);
    }

    private void Bind(int pageindex)
    {
        string DepartmentID=string.Empty;
        if (Request["DepartmentID"] != null)
        {
            string Where = "";
            if (!Request["DepartmentID"].Substring(0, 2).Equals("13"))
                DepartmentID = "13" + Request["DepartmentID"];
            else
                DepartmentID = Request["DepartmentID"];

            if (DepartmentID.Substring(4, 1).Equals("2"))
                Where = " GroupID='KSTP' And ParentID='KS0001' Order By ItemID";

            if (DepartmentID.Substring(4, 1).Equals("3") || DepartmentID.Substring(4, 1).Equals("1"))
                Where = " GroupID='KSTP' And ParentID='KS0000' Order By ItemID";


            List<Yipusoft.Common.Model.CodeItemInfo> list = Yipusoft.Common.BLL.CodeItem.GetList2(Where);
            if (list == null)
                return;
            List<Yipusoft.Common.Model.CodeItemInfo> list2 = new List<Yipusoft.Common.Model.CodeItemInfo>();
            int PageSize = 6;
            int StartPage = PageSize * (pageindex + 1) - 6;
            for (int i = StartPage; i < StartPage + PageSize; i++)
            {
                if (i == list.Count()) 
                break;
                list2.Add(list[i]);
            }
           
            //List<Yipusoft.MapInfo.Model.DepartmentPhotoInfo> list = Yipusoft.MapInfo.BLL.DepartmentPhoto.GetPhotoByDepartmentID("DepartmentId='" + DepartmentID + "' And OrderID is not null ", "OrderID", "ASC", 6, pageindex);
            

            this.DltList.DataSource = list2;
            this.ListPageContral1.ItemCount = list.Count();
            this.DltList.DataBind();       


        }
    }

    public string GetPicUrl(object objID)
    {
        if (objID == null)
            return "/Images/none.jpg";
        Yipusoft.MapInfo.Model.DepartmentPhotoInfo model = null;
        string DepartmentID = string.Empty;
        if (Request["DepartmentID"] != null)
        {
            string Where = "";
            if (!Request["DepartmentID"].Substring(0, 2).Equals("13"))
                DepartmentID = "13" + Request["DepartmentID"];
            else
                DepartmentID = Request["DepartmentID"];

            List<Yipusoft.MapInfo.Model.DepartmentPhotoInfo> list= Yipusoft.MapInfo.BLL.DepartmentPhoto.GetPhotoListByDepartmentID(DepartmentID);

            model = list.Where(o => o.PhotoName.Equals(objID.ToString())).Count() == 1 ? list.Where(o => o.PhotoName.Equals(objID.ToString())).Single() : null;
            if (model == null)
                return "/Images/none.jpg";

            
        }
        return model.PhotoUrl;
    }
}
